<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar
          height="50"
          :border-bottom="false"
          title="退款售后"
          title-size="36"
          title-color="#333"
        ></u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#10A28F"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item v-for="(sitem, sindex) in tabsList" class="swiperItem" :key="sindex">
          <z-paging
            ref="paging"
            v-model="itemList[sindex]"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :auto-show-back-to-top="true"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList[sindex]" :key="index1">
                <view class="order-top dis-flex flex-y-center flex-y-between">
                  <text class="dis-flex flex-y-center">单号:{{ item.no }}</text>
                  <text class="order-top-tip">
                    {{ item.statusName }}
                  </text>
                </view>
                <view class="layoutView">
                  <view class="order-goods" v-for="item2 in item.items" :key="item2.id">
                    <u-image
                      class="goods-img"
                      :src="item2.picUrl"
                      width="160rpx"
                      height="160rpx"
                      border-radius="10"
                    ></u-image>
                    <view class="orde-riget" style="flex: 1">
                      <view class="goods-title">
                        <text>{{ item2.spuName }}</text>
                      </view>
                      <view class="goods-speci">
                        <text v-if="item2.properties && item2.properties.length > 0"
                          >{{ item2.properties[0].valueName }}
                        </text>
                        <text class="goods-num">x{{ item2.count }}</text>
                      </view>
                      <view class="goods-price" v-if="item2.afterSaleId">
                        <text>¥{{ (item2.price * 0.01).toFixed(2) }}</text>
                        <text
                          class="goods-refund"
                          v-if="
                            item2.afterSaleStatus === 10 ||
                            item2.afterSaleStatus === 20 ||
                            item2.afterSaleStatus === 30
                          "
                        >
                          退款进行中
                        </text>
                        <text class="goods-refund" v-else-if="item2.afterSaleStatus === 40">
                          等待平台退款
                        </text>
                        <text class="goods-refund" v-else-if="item2.afterSaleStatus === 50">
                          退款成功
                        </text>
                        <text class="goods-refund" v-else> 已终止退款</text>
                      </view>
                    </view>
                  </view>
                </view>
                <view class="price-total dis-flex flex-y-center flex-y-between">
                  <view>共{{ item.productCount }}件</view>
                  <view>
                    合计：
                    <text style="color: #fa453c">¥{{ (item.payPrice * 0.01).toFixed(2) }}</text>
                  </view>
                </view>
                <view class="btn-group" v-if="item.afterSaleStatus == 10">
                  <view class="solid-btn btn" @click.stop.prevent="onCheck(item)">确认退款</view>
                  <view class="hollow-btn btn" @click.stop.prevent="onRefush(item)">
                    拒绝退款
                  </view>
                  <view
                    v-if="item.afterSaleStatus == 30"
                    class="hollow-btn btn"
                    @click.stop.prevent="onRefushReceive(item)"
                  >
                    拒绝收货
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>

    <u-popup
      :closeable="true"
      width="550rpx"
      v-model="show5"
      mode="bottom"
      height="auto"
      border-rad
      border-radius="15"
    >
      <view class="popup-box">
        <view class="popup-title"> 拒绝售后</view>
        <view style="margin-top: 40rpx">
          <textarea
            style="background-color: #efefef; padding: 10rpx; width: 690rpx; margin-top: 20rpx"
            v-model="refushform.auditReason"
            placeholder="请输入拒绝原因"
          ></textarea>
        </view>
        <view class="" style="margin-bottom: 100rpx"></view>
        <view class="fixed-wapper1">
          <view class="submit-btn" @click="pushRefush"> 确认拒绝</view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
import PayPopup from '@/components/PayPopup.vue'
import { BASE_URL, UP_URL } from '@/common/config'

export default {
  components: {
    PayPopup
  },
  data() {
    return {
      action: BASE_URL + UP_URL,
      imgStyle: {
        width: '12rem'
      },
      fileList: [],
      refushform: {
        auditReason: '',
        orderId: ''
      },
      show5: false,
      payOrderId: '',
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: '',
          key: 'all',
          count: 0
        },
        {
          name: '待审核',
          key: 'audit',
          status: 10,
          count: 0
        },
        {
          name: '待退款',
          key: 'platform',
          status: 40,
          count: 0
        },
        {
          name: '已退款',
          key: 'finish',
          status: 50,
          count: 0
        },
        {
          name: '已驳回',
          key: 'refuse',
          status: 62,
          count: 0
        }
      ],
      itemList: [[], [], [], [], []],
      order_id: ''
    }
  },
  onLoad(res) {
    this.current = 0
    this.scurrent = 0
    if (res.index) {
      this.current = Number(res.index) ? Number(res.index) : 0
      this.scurrent = Number(res.index) ? Number(res.index) : 0
    }
    this.$u.get('/app-api/trade/delivery/express/list', {}).then((res) => {
      this.exprees = res.data
    })
  },

  onShow() {
    let self = this
    this.queryList(1)
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      if (this.itemList[this.current].length == 0) {
        this.queryList(1)
      }
      // console.log('animationfinish',this.current,this.scurrent)
    },
    queryList(pageNo = 1, pageSize = 10) {
      if (pageNo == 1) {
        this.itemList[this.current] = []
      }
      this.$u
        .get('/app-api/trade/order/page-seller', {
          pageNo,
          pageSize,
          orderStatus: 'return',
          afterSaleStatus: this.tabsList[this.scurrent] ? this.tabsList[this.scurrent].status : ''
        })
        .then((res) => {
          this.$refs.paging[this.scurrent].complete(res.data.list)
        })
    },
    onCheck(item) {
      const self = this
      self.$u.post('/app-api/trade/after-sale/agree-by-order?orderId=' + item.id).then((res) => {
        if (res.code === 0) {
          self.$u.toast('确认成功')
          self.queryList()
        } else {
          self.$u.toast(res.msg)
        }
      })
    },
    pushRefush() {
      const self = this
      self.$u.post('/app-api/trade/after-sale/disagree', self.refushform).then((res) => {
        if (res.code === 0) {
          self.$u.toast('拒绝成功')
          self.refushform.orderId = ''
          self.refushform.auditReason = ''
          self.queryList()
          self.show5 = false
        } else {
          self.$u.toast(res.msg)
        }
      })
    },
    onRefushReceive(item) {
      const self = this
      self.$u.post('/app-api/trade/after-sale/refuse?orderId=' + item.id).then((res) => {
        if (res.code === 0) {
          self.$u.toast('拒绝成功')
          self.queryList()
        } else {
          self.$u.toast(res.msg)
        }
      })
    },
    onRefush(item) {
      this.refushform.orderId = item.id
      this.refushform.auditReason = ''
      this.show5 = true
    },
    beforeFileUpload(_index, list) {
      this.fileList = list
    },
    onFileRemove(_index, list) {
      this.fileList = list
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import url('order-list.css');
@import url('@/style/btn.css');

page {
  height: 100%;
  background: #f0f1f2;
}

.slot-btn {
  width: 200rpx;
  height: 200rpx;
  background: #f5f5f5;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-flow: column;
}
</style>
